import random
import threading
from queue import Queue
from time import sleep, time


def get_url_detail(queue):
    while True:
        url = queue.get()
        print('this is start get get_url_detail({}) !'.format(url))
        sleep(5)
        print('this is end get get_url_detail({}) !'.format(url))


def get_content_url(queue):
    while True:
        print('this is start get get_content_url !')
        queue.put('http://www.baidu.com/p/{}'.format(random.randint(0, 1000)))
        sleep(30)
        print('this is end get get_content_url !')


if __name__ == '__main__':
    url_queue = Queue(maxsize=200)
    while True:
        t1 = threading.Thread(target=get_content_url, args=(url_queue,))
        for i in range(5):
            detail_thread = threading.Thread(target=get_url_detail, args=(url_queue,))
            detail_thread.start()
        t1.start()
